"""
line dictionary loader

Load internal lookup:
  object = Lines('hammer', **kwargs)

Load an indice lookup outside of the python path:
  object = Lines('hammer',root="/tmp")

Pick a new set of lines from internal lookup:
  object.new('newlines')

Directly extract indices from internal lookup:
  indices = Lines('hammer').get('indices')

Directly access an air wavelength for a line in an internal lookup:
  air = Lines('hammer').get('indices')['VO-b']['air'][0]
"""

import os, sys

class Lines(object):
  """
  Loader for lines data. validation not implemented 
  """
  _root = "spectrallines"
  _lines = "newlines"

  def __init__(self, linelist, **kwargs):
    """init """
    self._lines = linelist

    if kwargs.has_key('root'):
      self._set_root(kwargs['root'])
      self._path = self._lines
    else:
      self._path = self._root + "." + self._lines

    self.__setattr__("_module",
                    __import__(self._path, fromlist=self._lines))

    if not kwargs.has_key('attrs'):
      kwargs['attrs'] = [foo for foo in self._module.__dict__.keys()
                        if foo[0] is not "_"]

    for foo in kwargs['attrs']:
      self.get(foo)

  def _set_root(self, root):
    if not sys.path.count(os.path.abspath(root)):
      sys.path.append(os.path.abspath(root))
      self._root = ''

  def get(self, attr):
    self.__setattr__(attr, getattr(self._module, attr, None))
    return getattr(self._module, attr, None)

  def new_lines(self, linelist, **kwargs):
    self.__init__(linelist, **kwargs)

  def validate(self):
    """
    have to make some requirements on the input line list
    """
    pass
